<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <!--输入框 可以设置type="hidden" 隐藏，外界看不见，但是可以提交数据 -->
                <input name="id" type="hidden" class="layui-input">
                <label class="layui-form-label">用户ID：</label>
                <div class="layui-input-block">
                    <input type="number" name="uId" lay-verify="required" lay-reqtext="用户ID是必填项,岂能为空" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">宠物ID：</label>
                <div class="layui-input-block">
                    <input type="number" name="pId" lay-verify="required" lay-reqtext="宠物ID是必填项，岂能为空？"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">修改时间:</label>
                    <div class="layui-input-block">
                        <input type="text" name="utime" id="date" autocomplete="off" class="layui-input">
                    </div>
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">服从命令：</label>
                    <div class="layui-input-block">
                        <select name="serveTrainItem.obeyOrder" type="number">
                            <option value="">请选择</option>
                            <option value="0">不需要</option>
                            <option value="1">需要</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">技巧训练：</label>
                    <div class="layui-input-block">
                        <select name="serveTrainItem.skillTraining" type="number">
                            <option value="">请选择</option>
                            <option value="0">不需要</option>
                            <option value="1">需要</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">行为纠正：</label>
                    <div class="layui-input-block">
                        <select name="serveTrainItem.behaviorCorrect" type="number">
                            <option value="">请选择</option>
                            <option value="0">不需要</option>
                            <option value="1">需要</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="demo1">修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/jquery-3.6.0.min.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#date'
        });
        //监听提交
        form.on('submit(demo1)', function (data) {
            //ajax 调用接口
            $.post("/api/serveTrain/update.do",data.field,function(res){
                if(res.code==2){
                    //修改成功
                    layer.msg('修改成功！');
                    //关闭当前页面
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }else{
                    //新增失败
                    layer.msg('修改失败！');
                }
            });
            return false;
        });
        //获取要编辑的内容
        var json=localStorage.getItem("servetrain");
        console.log(json);
        //表单初始赋值
        form.val('example',eval("("+json+")"));
    });
</script>
</body>
</html>